﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
namespace CricketHub
{
    public class PlayerDetail
    {
      public  PlayerDetails plydeta;
        HttpWebRequest req;
        public void Request_player()
        {
            try
            {
                App id = App.Current as App;
                string ply_id = id.player_id;
                req = (HttpWebRequest)WebRequest.Create("http://www.myworkdemos.com/sports/CricketProfiles/Players.php?id=" + ply_id);//http://synd.cricbuzz.com/statsfeed/" + ply_id + ".xml");
                IAsyncResult result = (IAsyncResult)req.BeginGetResponse(new AsyncCallback(Resp), this);
            }
            catch (Exception kaa)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        MessageBox.Show("Please check the Network Connection");
                    });
            }
 
        }
        private void Resp(IAsyncResult result)
        {
            try
            {
                PlayerDetail plyinfo = (PlayerDetail)result.AsyncState;
                HttpWebRequest request = req;
                HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);
                Stream streamresponse = response.GetResponseStream();
                StreamReader reader = new StreamReader(streamresponse);
                string info = reader.ReadToEnd();
                plydeta.Update_ply_info(info);
            }
            catch (Exception kk)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show("Please check the Network Connection");
                });
 
            }
 
        }

    }
}
